package com.ruoyi.camp.service.impl;

import java.util.List;

import com.ruoyi.camp.domain.CCamp;
import com.ruoyi.camp.mapper.CCampMapper;
import com.ruoyi.common.utils.uuid.IdUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.camp.mapper.CollectMapper;
import com.ruoyi.camp.domain.Collect;
import com.ruoyi.camp.service.ICollectService;

/**
 * 收藏Service业务层处理
 * 
 * @author yeluochen
 * @date 2024-12-03
 */
@Service
public class CollectServiceImpl implements ICollectService 
{
    @Autowired
    private CollectMapper collectMapper;

    @Autowired
    private CCampMapper campMapper;

    /**
     * 查询收藏
     * 
     * @param collectId 收藏主键
     * @return 收藏
     */
    @Override
    public Collect selectCollectByCollectId(String collectId)
    {
        return collectMapper.selectCollectByCollectId(collectId);
    }
    // 小程序根据用户ID查询收藏列表
    @Override
    public List<CCamp> selectCollectByUserId(String userId)
    {
        Collect collect = new Collect();
        collect.setUserId(userId);
        return campMapper.selectCampListByCollectUserId(collect);
    }



    /**
     * 查询收藏列表
     * 
     * @param collect 收藏
     * @return 收藏
     */
    @Override
    public List<Collect> selectCollectList(Collect collect)
    {
        return collectMapper.selectCollectList(collect);
    }

    /**
     * 新增收藏
     * 
     * @param collect 收藏
     * @return 结果
     */
    @Override
    public int insertCollect(Collect collect)
    {
        List<Collect> result = collectMapper.selectCollectList(collect);
        if(result.size() == 0){
            collect.setCollectId(IdUtils.randomUUID());
            return collectMapper.insertCollect(collect);
        }else {
            return collectMapper.deleteCollectByCollectId(result.get(0).getCollectId());
        }

    }

    /**
     * 修改收藏
     * 
     * @param collect 收藏
     * @return 结果
     */
    @Override
    public int updateCollect(Collect collect)
    {
        return collectMapper.updateCollect(collect);
    }

    /**
     * 批量删除收藏
     * 
     * @param collectIds 需要删除的收藏主键
     * @return 结果
     */
    @Override
    public int deleteCollectByCollectIds(String[] collectIds)
    {
        return collectMapper.deleteCollectByCollectIds(collectIds);
    }

    /**
     * 删除收藏信息
     * 
     * @param collectId 收藏主键
     * @return 结果
     */
    @Override
    public int deleteCollectByCollectId(String collectId)
    {
        return collectMapper.deleteCollectByCollectId(collectId);
    }
}
